package de.koller.nadir;

import de.koller.aframe.gl.ADisplayGL;
import de.koller.aframe.gl.IARoot;
import de.koller.aframe.util.ALoop;
import de.koller.nadir.input.NInput;
import de.koller.nadir.render.NRender;
import de.koller.oceanFramework.tree.Child;
import de.koller.oceanFramework.tree.Sea3X;
import org.lwjgl.opengl.Display;

public class NRoot extends Sea3X implements IARoot {
	
	private final ALoop loop = new ALoop( this );
	private final ADisplayGL display = ADisplayGL.forceCreate( "Nadir", 1152, 648 );
	
	@Child public final NInput input = new NInput();
	@Child public final NRender render = new NRender();
	private long time = 0;
	
	@Override
	protected void init() {
		super.init();
		
		this.setIgnoreChildRender( true );
		display.start();
	}

	@Override
	protected void release() {
		super.release();
		display.stop();
	}

	@Override
	protected void update( int elapsedTime ) {
		super.update( elapsedTime );
		
		time += elapsedTime;
		
		if( Display.isCloseRequested() )
			stop();
	}
	
	@Override
	protected void render( int elapsedTime ) {
		super.render( elapsedTime );
		
		render.renderGame( elapsedTime );
		display.update();
	}
	
	public void start() {
		loop.begin();
	}
	
	public void stop() {
		loop.stop();
	}
	
	@Override
	public long getSystemTime() {
		return display.getTime();
	}

	public long getGameTime() {
		return time;
	}
	
}
